<template>
  <div class="container">
    <data-view ref= "childDataView"
      propViewKey="wm_in_order"
      propViewForm="wm/in-order/detail.vue"
      :propFlowKey="propFlowKey"
      :propViewFormTitle="cpPropViewFormTitle"
      :propPreQueryWrapper = "cpChildViewQueryWrapper"
      :propParam="getPropParam()"
      :propIsTdesign="true"
     @extra-button-click="extraButtonClick"
       :propFilterBtn="propFilterBtn"
    />


    <!--导入库存-->
    <customDrawer title="导入入库数据" ref="customDrawerImportStock"
                  :widthPx="500" :heightPx="500"
                  hideConfirm
    >
      <template #content>
        <dataImportArea
          downloadPath="/wm/stock/excelDownloadTempForImportStock"
          importPath="/wm/stock/excelImportForImportStock"
          @success="menuActiveCall"
          :sheetName="'库存'"
          helpMsg="
          1、【下载模板】维护好数据 -> 【选择文件】导入数据<br>
          2、<span class='span-msg-nopad'>对应的供应商和商品需要存在</span><br>
          3、<span class='span-msg-nopad'>产生已审核的入库单</span><br>
          4、<span class='span-msg-nopad'>根据供应商名称、商品名称、商品规格去查找相关商品 </span><br>
"
          ref="dataImportAreaImportStock"
        />
      </template>
    </customDrawer>
  </div>
</template>

<script>
import dataImportArea from '@/components/custom/bus/dataImportArea.vue'

export default {
  name: 'inorderSP',
  data() {
    return {
    }
  },
  components: {
    dataImportArea
  },
  props: ['propFlowKey', 'propParameter', 'busType'],
  created() {
  },
  computed: {
    // 业务类型
    cpBusType() {
      if (!this.busType) {
        return this.constCommon.dictType.wmInOrderTypeInAsn
      }
      return this.busType
    },
    // 业务类型
    cpPropViewFormTitle() {
      return this.constCommon.dictType.wmInOrderTypeMap[this.cpBusType]
    },

    // 查询条件
    cpChildViewQueryWrapper() {
      let wrapper = this.$newWrapper()
      if (this.cpBusType == this.constCommon.dictType.wmInOrderTypeInAsn) {
        wrapper.in('busType', [this.cpBusType,this.constCommon.dictType.wmInOrderTypeInPackage])
      } else {
        wrapper.eq('busType', this.cpBusType)
      }
      return wrapper
    }
  },
  methods: {
    menuActiveCall() {
      this.$refs.childDataView.fetchData()
    },
    getPropParam() {
      return {matrBaseType: this.utils.getMtrBaseType(this),busType: this.cpBusType}
    },
    extraButtonClick(para) {
      let {key: buttonKey} = para.button
      if (buttonKey == 'importWi') {
        this.$refs.dataImportAreaImportStock.clear()
        this.$refs.customDrawerImportStock.show()
      }
    },

    // 过滤显示按钮
    propFilterBtn(btnList) {
      // 只读状态，隐藏相关操作按钮
      if (this.constCommon.dictType.wmInOrderTypeInManual != this.busType) {
        btnList =  btnList.filter(btn => !['importWi'].includes(btn.code))
      }
      return btnList
    }
  }
}
</script>
